package Form;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Image;
import java.awt.Insets;
import java.awt.Toolkit;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;

import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JSpinner;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.SpinnerNumberModel;

import Control.Workshop_UpdateWorkshop_Controller;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

@SuppressWarnings("serial")
public class Workshop_UpdateWorkshop_Form extends JPanel{
	//Class Attributes
	private JLabel lblTitle;
	private JLabel lblWorkshopid;
	private JLabel lblWorkshopDate;
	private JLabel workshopDate;
	private JLabel lblCategory;
	private JComboBox category;
	private JLabel lblDescription;
	private JScrollPane scrollPane;
	private JTextArea description;
	private JLabel lblVenue;
	private JTextField venue;
	private JLabel lblDatetime;
	private JSpinner startDateTime;
	private JLabel lblTo;
	private JSpinner endDateTime;
	private JLabel lblCapacity;
	private JSpinner capacity;
	private JLabel lblTrainer;
	private JComboBox trainerNameCombo;
	private JCheckBox newTrainer;
	private JLabel lblTrainerName;
	private JTextField trainerName;
	private JLabel lblContactNo;
	private JTextField contactNo;
	private JLabel lblStatus;
	private JComboBox status;
	private JButton btnUpdate;
	private JButton btnReset;
	private JLabel lblBG;
	private JLabel lblGrayBG;
	
	//Object Attributes
	private Workshop_WorkshopMain_Form parser;
	private Workshop_UpdateWorkshop_Controller control;
	
	public Workshop_WorkshopMain_Form getParser() {
		return parser;
	}

	public void setParser(Workshop_WorkshopMain_Form parser) {
		this.parser = parser;
	}

	public Workshop_UpdateWorkshop_Controller getControl() {
		return control;
	}

	public void setControl(Workshop_UpdateWorkshop_Controller control) {
		this.control = control;
	}
	
	public Workshop_UpdateWorkshop_Form(Workshop_WorkshopMain_Form parser) {
		this.setParser(parser);

		GridBagLayout gridBagLayout = new GridBagLayout();
		gridBagLayout.columnWidths = new int[] {15, 95, 67, 68, 38, 85, 90, 15};
		gridBagLayout.rowHeights = new int[] {30, 30, 30, 75, 25, 25, 25, 25, 25, 25, 25, 25, 11};
		gridBagLayout.columnWeights = new double[]{1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0};
		gridBagLayout.rowWeights = new double[]{0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0};
		setLayout(gridBagLayout);
		GridBagConstraints gbc_lblTitle = new GridBagConstraints();
		gbc_lblTitle.gridwidth = 6;
		gbc_lblTitle.anchor = GridBagConstraints.SOUTHWEST;
		gbc_lblTitle.insets = new Insets(0, 0, 2, 5);
		gbc_lblTitle.gridx = 1;
		gbc_lblTitle.gridy = 0;
		add(getLblTitle(), gbc_lblTitle);
		GridBagConstraints gbc_lblWorkshopid = new GridBagConstraints();
		gbc_lblWorkshopid.insets = new Insets(0, 0, 5, 5);
		gbc_lblWorkshopid.gridx = 6;
		gbc_lblWorkshopid.gridy = 0;
		add(getLblWorkshopid(), gbc_lblWorkshopid);
		GridBagConstraints gbc_lblWorkshopDate = new GridBagConstraints();
		gbc_lblWorkshopDate.anchor = GridBagConstraints.NORTHWEST;
		gbc_lblWorkshopDate.insets = new Insets(0, 0, 5, 5);
		gbc_lblWorkshopDate.gridx = 1;
		gbc_lblWorkshopDate.gridy = 1;
		add(getLblWorkshopDate(), gbc_lblWorkshopDate);
		GridBagConstraints gbc_workshopDate = new GridBagConstraints();
		gbc_workshopDate.anchor = GridBagConstraints.NORTHWEST;
		gbc_workshopDate.gridwidth = 2;
		gbc_workshopDate.insets = new Insets(0, 0, 5, 5);
		gbc_workshopDate.gridx = 2;
		gbc_workshopDate.gridy = 1;
		add(getWorkshopDate(), gbc_workshopDate);
		GridBagConstraints gbc_lblCategory = new GridBagConstraints();
		gbc_lblCategory.anchor = GridBagConstraints.EAST;
		gbc_lblCategory.insets = new Insets(0, 0, 5, 5);
		gbc_lblCategory.gridx = 1;
		gbc_lblCategory.gridy = 2;
		add(getLblCategory(), gbc_lblCategory);
		GridBagConstraints gbc_category = new GridBagConstraints();
		gbc_category.gridwidth = 2;
		gbc_category.insets = new Insets(0, 0, 5, 5);
		gbc_category.fill = GridBagConstraints.HORIZONTAL;
		gbc_category.gridx = 2;
		gbc_category.gridy = 2;
		add(getCategory(), gbc_category);
		GridBagConstraints gbc_lblDescription = new GridBagConstraints();
		gbc_lblDescription.anchor = GridBagConstraints.NORTHEAST;
		gbc_lblDescription.insets = new Insets(0, 0, 5, 5);
		gbc_lblDescription.gridx = 1;
		gbc_lblDescription.gridy = 3;
		add(getLblDescription(), gbc_lblDescription);
		GridBagConstraints gbc_scrollPane = new GridBagConstraints();
		gbc_scrollPane.gridwidth = 5;
		gbc_scrollPane.insets = new Insets(0, 0, 5, 5);
		gbc_scrollPane.fill = GridBagConstraints.BOTH;
		gbc_scrollPane.gridx = 2;
		gbc_scrollPane.gridy = 3;
		add(getScrollPane(), gbc_scrollPane);
		GridBagConstraints gbc_lblVenue = new GridBagConstraints();
		gbc_lblVenue.anchor = GridBagConstraints.EAST;
		gbc_lblVenue.insets = new Insets(0, 0, 5, 5);
		gbc_lblVenue.gridx = 1;
		gbc_lblVenue.gridy = 4;
		add(getLblVenue(), gbc_lblVenue);
		GridBagConstraints gbc_venue = new GridBagConstraints();
		gbc_venue.gridwidth = 2;
		gbc_venue.insets = new Insets(0, 0, 5, 5);
		gbc_venue.fill = GridBagConstraints.HORIZONTAL;
		gbc_venue.gridx = 2;
		gbc_venue.gridy = 4;
		add(getVenue(), gbc_venue);
		GridBagConstraints gbc_lblDatetime = new GridBagConstraints();
		gbc_lblDatetime.anchor = GridBagConstraints.EAST;
		gbc_lblDatetime.insets = new Insets(0, 0, 5, 5);
		gbc_lblDatetime.gridx = 1;
		gbc_lblDatetime.gridy = 5;
		add(getLblDatetime(), gbc_lblDatetime);
		GridBagConstraints gbc_startDateTime = new GridBagConstraints();
		gbc_startDateTime.gridwidth = 2;
		gbc_startDateTime.fill = GridBagConstraints.HORIZONTAL;
		gbc_startDateTime.insets = new Insets(0, 0, 5, 5);
		gbc_startDateTime.gridx = 2;
		gbc_startDateTime.gridy = 5;
		add(getStartDateTime(), gbc_startDateTime);
		GridBagConstraints gbc_lblTo = new GridBagConstraints();
		gbc_lblTo.insets = new Insets(0, 0, 5, 5);
		gbc_lblTo.gridx = 4;
		gbc_lblTo.gridy = 5;
		add(getLblTo(), gbc_lblTo);
		GridBagConstraints gbc_endDateTime = new GridBagConstraints();
		gbc_endDateTime.gridwidth = 2;
		gbc_endDateTime.fill = GridBagConstraints.HORIZONTAL;
		gbc_endDateTime.insets = new Insets(0, 0, 5, 5);
		gbc_endDateTime.gridx = 5;
		gbc_endDateTime.gridy = 5;
		add(getEndDateTime(), gbc_endDateTime);
		GridBagConstraints gbc_lblCapacity = new GridBagConstraints();
		gbc_lblCapacity.anchor = GridBagConstraints.EAST;
		gbc_lblCapacity.insets = new Insets(0, 0, 5, 5);
		gbc_lblCapacity.gridx = 1;
		gbc_lblCapacity.gridy = 6;
		add(getLblCapacity(), gbc_lblCapacity);
		GridBagConstraints gbc_capacity = new GridBagConstraints();
		gbc_capacity.fill = GridBagConstraints.HORIZONTAL;
		gbc_capacity.insets = new Insets(0, 0, 5, 5);
		gbc_capacity.gridx = 2;
		gbc_capacity.gridy = 6;
		add(getCapacity(), gbc_capacity);
		GridBagConstraints gbc_lblTrainer = new GridBagConstraints();
		gbc_lblTrainer.anchor = GridBagConstraints.EAST;
		gbc_lblTrainer.insets = new Insets(0, 0, 5, 5);
		gbc_lblTrainer.gridx = 1;
		gbc_lblTrainer.gridy = 7;
		add(getLblTrainer(), gbc_lblTrainer);
		GridBagConstraints gbc_trainerNameCombo = new GridBagConstraints();
		gbc_trainerNameCombo.gridwidth = 2;
		gbc_trainerNameCombo.insets = new Insets(0, 0, 5, 5);
		gbc_trainerNameCombo.fill = GridBagConstraints.HORIZONTAL;
		gbc_trainerNameCombo.gridx = 2;
		gbc_trainerNameCombo.gridy = 7;
		add(getTrainerNameCombo(), gbc_trainerNameCombo);
		GridBagConstraints gbc_newTrainer = new GridBagConstraints();
		gbc_newTrainer.anchor = GridBagConstraints.WEST;
		gbc_newTrainer.gridwidth = 2;
		gbc_newTrainer.insets = new Insets(0, 0, 5, 5);
		gbc_newTrainer.gridx = 4;
		gbc_newTrainer.gridy = 7;
		add(getNewTrainer(), gbc_newTrainer);
		GridBagConstraints gbc_lblTrainerName = new GridBagConstraints();
		gbc_lblTrainerName.anchor = GridBagConstraints.EAST;
		gbc_lblTrainerName.insets = new Insets(0, 0, 5, 5);
		gbc_lblTrainerName.gridx = 2;
		gbc_lblTrainerName.gridy = 8;
		add(getLblTrainerName(), gbc_lblTrainerName);
		GridBagConstraints gbc_trainerName = new GridBagConstraints();
		gbc_trainerName.gridwidth = 2;
		gbc_trainerName.insets = new Insets(0, 0, 5, 5);
		gbc_trainerName.fill = GridBagConstraints.HORIZONTAL;
		gbc_trainerName.gridx = 3;
		gbc_trainerName.gridy = 8;
		add(getTrainerName(), gbc_trainerName);
		GridBagConstraints gbc_lblContactNo = new GridBagConstraints();
		gbc_lblContactNo.anchor = GridBagConstraints.EAST;
		gbc_lblContactNo.insets = new Insets(0, 0, 5, 5);
		gbc_lblContactNo.gridx = 2;
		gbc_lblContactNo.gridy = 9;
		add(getLblContactNo(), gbc_lblContactNo);
		GridBagConstraints gbc_contactNo = new GridBagConstraints();
		gbc_contactNo.gridwidth = 2;
		gbc_contactNo.insets = new Insets(0, 0, 5, 5);
		gbc_contactNo.fill = GridBagConstraints.HORIZONTAL;
		gbc_contactNo.gridx = 3;
		gbc_contactNo.gridy = 9;
		add(getContactNo(), gbc_contactNo);
		GridBagConstraints gbc_lblStatus = new GridBagConstraints();
		gbc_lblStatus.anchor = GridBagConstraints.EAST;
		gbc_lblStatus.insets = new Insets(0, 0, 5, 5);
		gbc_lblStatus.gridx = 1;
		gbc_lblStatus.gridy = 10;
		add(getLblStatus(), gbc_lblStatus);
		GridBagConstraints gbc_status = new GridBagConstraints();
		gbc_status.gridwidth = 2;
		gbc_status.insets = new Insets(0, 0, 5, 5);
		gbc_status.fill = GridBagConstraints.HORIZONTAL;
		gbc_status.gridx = 2;
		gbc_status.gridy = 10;
		add(getStatus(), gbc_status);
		GridBagConstraints gbc_btnUpdate = new GridBagConstraints();
		gbc_btnUpdate.insets = new Insets(0, 0, 5, 5);
		gbc_btnUpdate.gridx = 5;
		gbc_btnUpdate.gridy = 11;
		add(getBtnUpdate(), gbc_btnUpdate);
		GridBagConstraints gbc_btnReset = new GridBagConstraints();
		gbc_btnReset.insets = new Insets(0, 0, 5, 5);
		gbc_btnReset.gridx = 6;
		gbc_btnReset.gridy = 11;
		add(getBtnReset(), gbc_btnReset);
		GridBagConstraints gbc_lblGrayBG = new GridBagConstraints();
		gbc_lblGrayBG.gridwidth = 8;
		gbc_lblGrayBG.gridheight = 13;
		gbc_lblGrayBG.gridx = 0;
		gbc_lblGrayBG.gridy = 0;
		add(getLblGrayBG(), gbc_lblGrayBG);
		GridBagConstraints gbc_lblBG = new GridBagConstraints();
		gbc_lblBG.gridwidth = 8;
		gbc_lblBG.gridheight = 13;
		gbc_lblBG.gridx = 0;
		gbc_lblBG.gridy = 0;
		add(getLblBG(), gbc_lblBG);

		this.setControl(new Workshop_UpdateWorkshop_Controller(this));
	}

	public JLabel getLblTitle() {
		if (lblTitle == null) {
			lblTitle = new JLabel("Update Workshop");
			lblTitle.setForeground(Color.LIGHT_GRAY);
			lblTitle.setFont(new Font("Rockwell", Font.BOLD, 28));
		}
		return lblTitle;
	}
	public JLabel getLblWorkshopid() {
		if (lblWorkshopid == null) {
			lblWorkshopid = new JLabel("");
			lblWorkshopid.setForeground(Color.WHITE);
			lblWorkshopid.setBackground(new Color(0, 0, 0, 180));
			lblWorkshopid.setOpaque(true);
		}
		return lblWorkshopid;
	}
	public JLabel getLblWorkshopDate() {
		if (lblWorkshopDate == null) {
			lblWorkshopDate = new JLabel("Updated on:");
			lblWorkshopDate.setFont(new Font("Tahoma", Font.BOLD, 13));
			lblWorkshopDate.setForeground(Color.WHITE);
			lblWorkshopDate.setBackground(new Color(0, 0, 0, 180));
			lblWorkshopDate.setOpaque(true);
		}
		return lblWorkshopDate;
	}
	public JLabel getWorkshopDate() {
		if (workshopDate == null) {
			workshopDate = new JLabel("");
			workshopDate.setFont(new Font("Tahoma", Font.BOLD, 13));
			workshopDate.setForeground(Color.WHITE);
			workshopDate.setBackground(new Color(0, 0, 0, 180));
			workshopDate.setOpaque(true);
		}
		return workshopDate;
	}
	public JLabel getLblCategory() {
		if (lblCategory == null) {
			lblCategory = new JLabel("Category:");
			lblCategory.setFont(new Font("Tahoma", Font.BOLD, 13));
			lblCategory.setForeground(Color.WHITE);
			lblCategory.setBackground(new Color(0, 0, 0, 180));
			lblCategory.setOpaque(true);
		}
		return lblCategory;
	}
	public JComboBox getCategory() {
		if (category == null) {
			category = new JComboBox();
			category.setBorder(BorderFactory.createLineBorder(Color.black, 2));
		}
		return category;
	}
	public JLabel getLblDescription() {
		if (lblDescription == null) {
			lblDescription = new JLabel("Description:");
			lblDescription.setFont(new Font("Tahoma", Font.BOLD, 13));
			lblDescription.setForeground(Color.WHITE);
			lblDescription.setBackground(new Color(0, 0, 0, 180));
			lblDescription.setOpaque(true);
			
		}
		return lblDescription;
	}
	public JScrollPane getScrollPane() {
		if (scrollPane == null) {
			scrollPane = new JScrollPane();
			scrollPane.setViewportView(getDescription());
		}
		return scrollPane;
	}
	public JTextArea getDescription() {
		if (description == null) {
			description = new JTextArea();
			description.setFont(new Font("Tahoma", Font.PLAIN, 13));
			description.setLineWrap(true);
			description.setBorder(BorderFactory.createLineBorder(Color.black, 2));
		}
		return description;
	}
	public JLabel getLblVenue() {
		if (lblVenue == null) {
			lblVenue = new JLabel("Venue:");
			lblVenue.setFont(new Font("Tahoma", Font.BOLD, 13));
			lblVenue.setForeground(Color.WHITE);
			lblVenue.setBackground(new Color(0, 0, 0, 180));
			lblVenue.setOpaque(true);
		}
		return lblVenue;
	}
	public JTextField getVenue() {
		if (venue == null) {
			venue = new JTextField();
			venue.setColumns(10);
			venue.setBorder(BorderFactory.createLineBorder(Color.black, 2));
		}
		return venue;
	}
	public JLabel getLblDatetime() {
		if (lblDatetime == null) {
			lblDatetime = new JLabel("Date/Time:");
			lblDatetime.setFont(new Font("Tahoma", Font.BOLD, 13));
			lblDatetime.setForeground(Color.WHITE);
			lblDatetime.setBackground(new Color(0, 0, 0, 180));
			lblDatetime.setOpaque(true);
		}
		return lblDatetime;
	}
	public JSpinner getStartDateTime() {
		if (startDateTime == null) {
			startDateTime = new JSpinner();
			startDateTime.setBorder(BorderFactory.createLineBorder(Color.black, 2));
		}
		return startDateTime;
	}
	public JLabel getLblTo() {
		if (lblTo == null) {
			lblTo = new JLabel("to");
			lblTo.setForeground(Color.WHITE);
			lblTo.setBackground(new Color(0, 0, 0, 180));
			lblTo.setOpaque(true);
		}
		return lblTo;
	}
	public JSpinner getEndDateTime() {
		if (endDateTime == null) {
			endDateTime = new JSpinner();
			endDateTime.setBorder(BorderFactory.createLineBorder(Color.black, 2));
		}
		return endDateTime;
	}
	public JLabel getLblCapacity() {
		if (lblCapacity == null) {
			lblCapacity = new JLabel("Capacity:");
			lblCapacity.setFont(new Font("Tahoma", Font.BOLD, 13));
			lblCapacity.setForeground(Color.WHITE);
			lblCapacity.setBackground(new Color(0, 0, 0, 180));
			lblCapacity.setOpaque(true);
		}
		return lblCapacity;
	}
	public JSpinner getCapacity() {
		if (capacity == null) {
			capacity = new JSpinner();
			capacity.setModel(new SpinnerNumberModel(10, 10, 30, 1));
			capacity.setBorder(BorderFactory.createLineBorder(Color.black, 2));
		}
		return capacity;
	}
	public JLabel getLblTrainer() {
		if (lblTrainer == null) {
			lblTrainer = new JLabel("Trainer:");
			lblTrainer.setFont(new Font("Tahoma", Font.BOLD, 13));
			lblTrainer.setForeground(Color.WHITE);
			lblTrainer.setBackground(new Color(0, 0, 0, 180));
			lblTrainer.setOpaque(true);
		}
		return lblTrainer;
	}
	public JComboBox getTrainerNameCombo() {
		if (trainerNameCombo == null) {
			trainerNameCombo = new JComboBox();
			trainerNameCombo.setBorder(BorderFactory.createLineBorder(Color.black, 2));
		}
		return trainerNameCombo;
	}
	public JCheckBox getNewTrainer() {
		if (newTrainer == null) {
			newTrainer = new JCheckBox("New Trainer");
			newTrainer.addItemListener(new ItemListener() {
				public void itemStateChanged(ItemEvent e) {
					control.setTrainerDetails();
				}
			});
		}
		return newTrainer;
	}
	public JLabel getLblTrainerName() {
		if (lblTrainerName == null) {
			lblTrainerName = new JLabel("Trainer Name:");
			lblTrainerName.setFont(new Font("Tahoma", Font.BOLD, 13));
			lblTrainerName.setForeground(Color.WHITE);
			lblTrainerName.setBackground(new Color(0, 0, 0, 180));
			lblTrainerName.setOpaque(true);
		}
		return lblTrainerName;
	}
	public JTextField getTrainerName() {
		if (trainerName == null) {
			trainerName = new JTextField();
			trainerName.setEditable(false);
			trainerName.setBorder(BorderFactory.createLineBorder(Color.black, 2));
		}
		return trainerName;
	}
	public JLabel getLblContactNo() {
		if (lblContactNo == null) {
			lblContactNo = new JLabel("Contact No:");
			lblContactNo.setFont(new Font("Tahoma", Font.BOLD, 13));
			lblContactNo.setForeground(Color.WHITE);
			lblContactNo.setBackground(new Color(0, 0, 0, 180));
			lblContactNo.setOpaque(true);
		}
		return lblContactNo;
	}
	public JTextField getContactNo() {
		if (contactNo == null) {
			contactNo = new JTextField();
			contactNo.setEditable(false);
			contactNo.setBorder(BorderFactory.createLineBorder(Color.black, 2));
		}
		return contactNo;
	}
	public JLabel getLblStatus() {
		if (lblStatus == null) {
			lblStatus = new JLabel("Status:");
			lblStatus.setFont(new Font("Tahoma", Font.BOLD, 13));
			lblStatus.setForeground(Color.WHITE);
			lblStatus.setBackground(new Color(0, 0, 0, 180));
			lblStatus.setOpaque(true);
		}
		return lblStatus;
	}
	public JComboBox getStatus() {
		if (status == null) {
			status = new JComboBox();
			status.setBorder(BorderFactory.createLineBorder(Color.black, 2));
		}
		return status;
	}
	public JButton getBtnUpdate() {
		if (btnUpdate == null) {
			btnUpdate = new JButton("Update");
			btnUpdate.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent arg0) {
					int selection = JOptionPane.showConfirmDialog(null, "Are you sure you want to update?", "Confirmation", JOptionPane.YES_NO_OPTION); 
					if(selection == JOptionPane.YES_OPTION){
						control.updateWorkshop();
					}
				}
			});
		}
		return btnUpdate;
	}
	public JButton getBtnReset() {
		if (btnReset == null) {
			btnReset = new JButton("Reset");
			btnReset.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent e) {
					control.generateSelectedWorkshop();
				}
			});
		}
		return btnReset;
	}
	public JLabel getLblBG() {
		if (lblBG == null) {
			lblBG = new JLabel("");
			lblBG.setIcon(new ImageIcon(Toolkit.getDefaultToolkit().createImage("Resources/Images/Workshop/workshop.jpg").getScaledInstance(500, 390, Image.SCALE_DEFAULT)));
		}
		return lblBG;
	}
	public JLabel getLblGrayBG() {
		if (lblGrayBG == null) {
			lblGrayBG = new JLabel("");
			lblGrayBG.setPreferredSize(new Dimension(480, 380));
			lblGrayBG.setBackground(new Color(0, 0, 0, 180));
			lblGrayBG.setOpaque(true);			
		}
		return lblGrayBG;
	}
}
